package com.cy.pj.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Aspect
@Component
public class CacheAspect {
    private Map<String, Object> cache = new ConcurrentHashMap<>();

    @Pointcut("bean(moduleServiceImpl)")
    public void doCache() {}

    @Around("doCache()")
    public Object aroud(ProceedingJoinPoint joinPoint) throws Throwable {
        Object obj = cache.get("userPer");
        if (obj != null) {
            return obj;
        }
        obj = joinPoint.proceed();
        cache.put("userPer",obj);
        return obj;
    }
}
